-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite: Improve handling of preview annotations #28798
base: next
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
5 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
View your CI Pipeline Execution ↗ for commit ba7be49.
☁️ Nx Cloud last updated this comment at |
Thank you for the PR @tobiasdiez. Could you have a look at why the CI is failing? |
…into previewAnno
Tests are passing now. |
@tobiasdiez I think I may have broken something when i merged in the base branch, but I'm not sure what. Can you assist? |
Thanks for your help! The tests should pass now, but there are ts errors during build. I have no idea where they are coming from. Do you? |
Managed to fix the tests, so this is good to go from my side. @ndelangen @tmeasday please review when you have a bit of spare time. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need someone who is more familiar with the vite builder to review this.
I have a couple qns:
Are we absolutely (haha) sure the absolute paths don't end up in the bundle anywhere? I'd like to verify this.
This is fixed by using normalize from the pathe package, which converts this to /."
Should we use slash
for this which is an existing dependency?
code/builders/builder-vite/src/codegen-modern-iframe-script.test.ts
Outdated
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
Before | After | Difference | |
---|---|---|---|
Dependency count | 7 | 7 | 0 |
Self size | 1.89 MB | 1.89 MB | 0 B |
Dependency size | 10.70 MB | 10.74 MB | 🚨 +43 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/cli
Before | After | Difference | |
---|---|---|---|
Dependency count | 393 | 393 | 0 |
Self size | 496 KB | 496 KB | 0 B |
Dependency size | 77.68 MB | 77.72 MB | 🚨 +44 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/codemod
Before | After | Difference | |
---|---|---|---|
Dependency count | 273 | 273 | 0 |
Self size | 612 KB | 612 KB | 0 B |
Dependency size | 67.58 MB | 67.62 MB | 🚨 +43 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/source-loader
Before | After | Difference | |
---|---|---|---|
Dependency count | 5 | 5 | 0 |
Self size | 41 KB | 41 KB | 0 B |
Dependency size | 10.64 MB | 10.68 MB | 🚨 +43 KB 🚨 |
Bundle Size Analyzer | Link | Link |
…ewAnno # Conflicts: # code/builders/builder-vite/src/codegen-modern-iframe-script.ts
I tried to see if I can fix the CI errors, but running
Also, how do I run vitest on a single file? I thought |
Is there anything I can do to get this merged soon? It's the last annoying issue for the nuxt module (at least for now ;-)) This should also fix #29620 and thus may replace #29639 @valentinpalkovic |
What I did
While working on the Nuxt integration, I noticed a couple of issues with how the preview annotations are handled. Namely:
optimizeDeps
(one of them is from Vite: Add jsdoc-type-pratt-parser tooptimizeDeps
#29179).node_modules
likenode_modules/packageA/node_modules/storybook
are truncated to the last package (storybook
in the example), which then cannot be resolved. This is fixed by always resolving the preview annotation paths to absolute paths and using them. The code contained a few remarks that vite appearently has problems with absolute paths, but as far as I'm aware vite handles absolute paths perfectly fine.\
as path separator. This is fixed by usingnormalize
from thepathe
package, which converts this to/
.The code to create the preview annotation imports is inspired by https://github.com/nuxt/nuxt/blob/754fc30e5d0fe506ee3218f9c4a11fa047e3553f/packages/nuxt/src/core/templates.ts#L61-L76
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
I've run and added a few tests. Still have to figure out how to test the sandboxes.
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>
Greptile Summary
Improved handling of preview annotations in the Vite builder for Storybook, addressing path normalization and import issues.
code/builders/builder-vite/package.json
: Addedknitwork
,pathe
, andslash
dependencies for better path handling.code/builders/builder-vite/src/codegen-modern-iframe-script.ts
: Updated to generate absolute paths for preview annotations and improved HMR logic.code/builders/builder-vite/src/utils/process-preview-annotation.ts
: Replacedpath
withpathe
for normalization and added deprecation warning for object-based annotations.code/builders/builder-vite/src/codegen-modern-iframe-script.test.ts
: Added unit tests forgenerateModernIframeScriptCodeFromPreviews
.code/builders/builder-vite/src/utils/process-preview-annotation.test.ts
: Updated tests to ensure correct path handling, especially for Windows paths.